<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	float fFreeMemory=(float)Runtime.getRuntime().freeMemory();
	float fTotalMemory=(float)Runtime.getRuntime().totalMemory();
	float fUsedMemory = fTotalMemory - fFreeMemory;
	float fPercent=fFreeMemory/fTotalMemory*100;

class EnvServlet
{
	public long timeUse=0;
	public Hashtable htParam=new Hashtable();
	private Hashtable htShowMsg=new Hashtable();
	public void setHashtable()
	{
		Properties me=System.getProperties();
		Enumeration em=me.propertyNames();
		while(em.hasMoreElements())
		{
			String strKey=(String)em.nextElement();
			String strValue=me.getProperty(strKey);
			htParam.put(strKey,strValue);
		}
	}	
	public String queryHashtable(String strKey)
	{
		strKey=(String)htParam.get(strKey);
		return strKey;
	}
}

	EnvServlet env=new EnvServlet();
	env.setHashtable();
	String action=new String(" ");
	String act=new String("action");
	if(request.getQueryString()!=null&&request.getQueryString().indexOf(act,0)>=0)action=request.getParameter(act);
%>
<!DOCTYPE html>
<html lang="zh-cn">
  <head>
    <title>OrangePi 系统信息</title>
	<meta name="viewport" content="width=device-width,target-densitydpi=high-dpi,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
	<jsp:include page="/comm/link.jsp" />
	
  </head>
  <body>
	<jsp:include page="/comm/header.jsp" />

	<div class="container" id="main" >
		<div class="row">
			<div class="col-md-12">
				<div class="panel panel-success">
			 		<div class="panel-heading">
			 			<h3 class="panel-title">Tomcat容器信息</h3>
			 		</div>
			 		<ul class="list-group">
			 			<li class="list-group-item">
			 					<p>容器内存：<%=String.format("%.2f", fUsedMemory/1024/1024)%>M / <%=String.format("%.2f", fTotalMemory/1024/1024)%>M </p>
								<div style="width:200px; height:10px; background:#f00; font-size:1px">
									<div style="float:right; background:#0f0; width:<%=(int)(fPercent*2)%>px; font-size:1px; height:10px"></div>
								</div>
							</li>
			 				    <li class="list-group-item">用户目录：<%=env.queryHashtable("user.dir")%></li>
						        <li class="list-group-item">端　　口：	<%= request.getServerPort() %> </li>
			 				     <li class="list-group-item">JAVA运行环境名称：<%=env.queryHashtable("java.runtime.name")%></li>
						         <li class="list-group-item">
						            JAVA运行环境说明书名称：<%=env.queryHashtable("java.specification.name")%>/
						           <%=env.queryHashtable("java.specification.version")%>
						           </li>
						         <li class="list-group-item">JDK版本：<%=System.getProperty("java.version") %></li>
						         <li class="list-group-item">
						         	<div class="alert alert-info success_msg hide fade in">
											<button class="close" data-dismiss="alert" data-original-title="" title="">
										 		<span>×</span>
										 	</button>				
										 	<p>操作成功...</p>		         	
						         	</div>
						         	<div class="alert alert-danger error_msg hide fade in">
										<button class="close" data-dismiss="alert" data-original-title="" title="">
										 		<span>×</span>
										 	</button>		
										 	<p>操作失败...</p>
									</div>
						         		操作：
						         		<button class="btn btn-danger" onclick="sendCommand(this,'tomcatStop');" data-loading-text="关闭中..." >关闭Tomcat</button>
						         		<button class="btn btn-success"  onclick="sendCommand(this,'tomcatResart');" data-loading-text="重启中...">重启Tomcat</button>
						         </li>
			 			</ul>
			 		</div>
			</div>
			<div class="col-md-12">
					  <div class="panel panel-success">
				 		<div class="panel-heading">
				 			<h3 class="panel-title">服务器连接速度</h3>
				 		</div>
				 			<table class="table table-striped table-hover table-responsive">
					        <tr> 
					          <td>接入设备</td>
					          <td>&nbsp;连接速度(理想值)</td>
					          <td>下载速度(理想值)</td>
					        </tr>
							<tr > 
						          <td>56k Modem</td>
						          <td>56 Kbps</td><td>&nbsp;7.0 k/s</td>
						        </tr>
						        <tr > 
						          <td>64k ISDN</td>
						          <td> 64 Kbps</td>
						          <td>&nbsp;8.0 k/s</td>
						        </tr>
						        <tr> 
						          <td>512k ADSL</td>
						          <td>512 Kbps</td>
						          <td>&nbsp;64.0 k/s</td>
						        </tr>
						        <tr> 
						          <td>1.5M Cable</td>
						          <td>1500 Kbps</td>
						          <td>&nbsp;187.5 k/s</td>
						        </tr>
						        <tr> 
						          <td>5M FTTP</td>
						          <td> 5000 Kbps</td>
						          <td>&nbsp;625.0 k/s</td>
						        </tr>
						        <tr > 
						          <td>当前连接速度</td>
									<%
									if(action.equals("SpeedTest"))
									{
											out.println("<script language='JavaScript'>var tSpeedStart=new Date();</script>")	;
											out.println("<!--\n");
											for(int i=0;i<1000;i++)
											{out.println("####################################################################################################");}
											out.println("-->\n");
											out.println("<script language='JavaScript'>var tSpeedEnd=new Date();</script>\n");
											out.println("<script language='JavaScript'>");
											out.println("var iSpeedTime=0;iSpeedTime=(tSpeedEnd - tSpeedStart) / 1000;");
											out.println("if(iSpeedTime>0) iKbps=Math.round(Math.round(100 * 8 / iSpeedTime * 10.5) / 10); else iKbps=10000 ;");
											out.println("var iShowPer=Math.round(iKbps / 100);");
											out.println("if(iShowPer<1) iShowPer=1;  else if(iShowPer>82)   iShowPer=82;");
											out.println("</script>\n");
											out.println("<script language='JavaScript'>") ;
											out.println("document.write('<td>' + iKbps + ' Kbps');");
											out.println("</script>\n");
											out.println("</td><td>&nbsp;<a href='?action=SpeedTest' title=测试连接速度><u>");
											out.println("<script language='JavaScript'>");
											out.println("document.write(Math.round(iKbps/8*10)/10+ ' k/s');");
											out.println("</script>\n") ;
											out.println("</u></a></td>");
										}
										else
										{out.println("<td></td><td>&nbsp;<a class='btn btn-info btn-sm' href='?action=SpeedTest' title=测试连接速度>开始测试</a></td>");}
										%>
						      </tr>
							</table>
				 		</div>
			 		</div>
			</div>
		</div>
	<jsp:include page="/comm/footer.jsp" />
		
  <script>
  		$(function(){
  			addActiveNav('Tomcat');
  		});
  		function sendCommand(thisBtn,type){
			var btn=$(thisBtn).button('loading');
  			var _url = "<%=path%>/server/serverAction?m="+type;
				var s=null;
				$.ajax({
					url:_url,
					success:function(resp){
						if(resp=='ok'){
							$(".success_msg").removeClass("hide");
						}else{
							$(".error_msg").removeClass("hide");
						}
						btn.button('reset');
				  	},
				  	error:function(){
				  		$(".error_msg").removeClass("hide");
				  		btn.button('reset');
				  	}
			    });
  		}
  		
  	</script>
	  
  </body>
</html>
